const mysql = require('mysql2/promise')

async function createDatabase () {
  try {
    console.log('🔍 连接到MySQL...')

    // 连接到MySQL（不指定数据库）
    const connection = await mysql.createConnection({
      host: 'localhost',
      port: 3306,
      user: 'root',
      password: 'GKL9512357'
    })

    console.log('✅ MySQL连接成功')

    // 创建数据库
    await connection.query(
      'CREATE DATABASE IF NOT EXISTS novel_platform CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'
    )
    console.log('✅ 数据库 novel_platform 创建成功')

    // 关闭连接
    await connection.end()
    console.log('🔌 连接已关闭')
  } catch (error) {
    console.error('❌ 创建数据库失败:', error.message)
  }
}

createDatabase()
